package com.example.util;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

public class FileIO {
	/**
	 * @param filename 文件位置,str文件内容 ,
	 * @param flag 是否追加
	 * */
	public static void print(String filename,String str,boolean flag){
		  BufferedOutputStream bos=null;
		  OutputStreamWriter writer = null;
		  BufferedWriter bw = null;
		try{
			  File f = new File(filename);
			  OutputStream os = new FileOutputStream(f,flag);
			   bos=new BufferedOutputStream(os);
			   writer = new OutputStreamWriter(bos);
			   bw = new BufferedWriter(writer);
			   bw.write("\r\n");//换行
			   bw.write(str);
			   bw.flush();
			   bw.close();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				bw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
